#pragma once
#include "DataAnalysis.h"
#include "PointCloudBase.h"
class GenHeadWithCylinder :public QObject, public PointCloudBase
{
	Q_OBJECT
public:
	GenHeadWithCylinder();
	~GenHeadWithCylinder();
	shared_ptr<pcl::PolygonMesh>  CalAndSaveMeshData(const list<DataAnalysis::suHeadData>& data, bool isShowData);
	void LoadAndCalData(string strPath, bool bIsNeedCal= false);
signals:
	void sign_ProgressChange(float fNewProgressValue, QString strInfo);
private:
	void InitCylinder();
	void InitEllipse();

	void DataToInfo(const vector<PPointCloudDef>& vHeadData, const PPointCloudDef& pFaceData, bool isSaveData = false);
	void DataToInfo(const list<DataAnalysis::suHeadData>& data, bool isSaveData = false);

	void InitData(bool isSaveData = false);
	shared_ptr<pcl::PolygonMesh>  CalMesh(bool isSaveData = false);
	
	int EvaluatePntValue(PCLPoint&pnt, const PCLPoint&pntFrom, const PCLPoint&pntTo, const float& fRadius = 0.005, const int& iAnticlockwise=0, const PCLPoint& pntPre = PCLPoint(), const float& fMaxDisDetal=-1);
	PPointCloudDef EvaluateHeadWithCylinder(float fHeight = 0.002);
	PPointCloudDef EvaluateHeadWithEllipse(float fHeight = 0.002);
	int EvaluatePntZ(float&z, PPointCloudDef pClound, POCTree pTree, float x, float y, float fWidth = 0.005, float fHeigth = 0.005);
	vector<PCLPoint> GetFaceData();
	vector<PCLPoint> GetFaceAllData();

	void PrepareDataSave(shared_ptr<pcl::PolygonMesh> pMesh, vector<PCLPoint>& vFacePnt);
	void PreparePntDataForSave(PCLPoint& pnt);

private:
	PCLPoint m_middlePnt;
	float m_fRadius, m_Height;

	PCLPoint m_ellipsePnt;
	float m_fXRadius, m_fYRadius, m_fZRadius;
	float m_faceRadius;
	PPointCloudDef m_pHeadData, m_faceTemplate;
	POCTree m_pTree;

};

